package com.xlg.file.center;

import com.xlg.file.center.handler.ExcelFileHandler;
import com.xlg.file.center.handler.Handler;
import com.xlg.file.center.utils.FileType;
import com.xlg.file.center.utils.Task;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author: 18310740596@163.com
 * @date: 2023-07-15 13:54:47
 * @version: v1.0
 * @describe: class responsibility
 */
public class ExcelTest {
    public static void main(String[] args) throws Exception {
        List<String> titles = new ArrayList<>();
        titles.add("name");
        titles.add("age");
        titles.add("addr");

        List<Object> contents = new ArrayList<>();

        for (int i = 0; i < 100; i++) {
            contents.add(User.builder().name("ZhangSan : " + i).age( i  + 1).addr("ChongQing : " + i).build());
        }

        Task task = Task.builder()
                .batchNo(UUID.randomUUID().toString())
                .uniqNo(UUID.randomUUID().toString())
                .titles(titles)
                .contents(contents)
                .fileType(FileType.XSLX)
                .build();


        Handler handler = Handler.builder()
                .filePath("D:\\test\\excel\\")
                .task(task)
                .fileLine(new AtomicInteger(0))
                .build();


        ExcelFileHandler excelFileHandler = new ExcelFileHandler();

        excelFileHandler.writeTitle(handler);
        System.out.println("文件标题写入完成..." + handler.getFile().getName());
        excelFileHandler.writeContent(handler);

        System.out.println("数据写入完成。。。。"  + handler.getFile().getName());

    }
}
